package Agents;

import AOP.Printer;
import Messages.AMessage;
import jade.core.AID;
import jade.core.Agent;
import jade.core.behaviours.CyclicBehaviour;
import jade.core.behaviours.TickerBehaviour;
import jade.lang.acl.ACLMessage;

@SuppressWarnings("serial")
public class User extends AUser
{	
	protected void setup()
	{
		preferenceTemperature = preferenceTemperature + (int) (Math.random() * 20);
		preferenceLight = preferenceLight + (int) (Math.random() * 50);
		preferenceNoiseMax = preferenceNoiseMax + (int) (Math.random() * 30);
		garbageWeight = garbageWeight + (int) (Math.random() * 10);
		garbageVolume = garbageVolume + (int) (Math.random() * 10);
		
		//System.out.println(garbageWeight);
		
		//TickerBehaviour used to broadcast the users preferences and location.
		addBehaviour(new TickerBehaviour(this, 2000)// AMessage.userInformConstant)
			{
				boolean lastLocationIsOut = false;
				protected void onTick()
				{
					boolean out = false;
					do
					{
						locationRow = (int) (Math.random() * 3);
						locationColumn = (int) (Math.random() * 3);
						if(locationColumn!=0 || locationRow!=0)
						{
							out = false;
						}
						else
						{
							out = true;
						}
					}
					while(lastLocationIsOut == out && lastLocationIsOut || (
								(locationColumn!=0 && locationRow==0) || (locationColumn==0 && locationRow!=0)) );
					lastLocationIsOut = out;
					
					String content = AMessage.constructMessage((Messageable)myAgent, AMessage.MessageType.USER);
					ACLMessage message = new ACLMessage(ACLMessage.INFORM);

					Printer.Print(myAgent.getLocalName(), "("+locationRow+","+locationColumn+")");
					message.setContent(content);
					AMessage.broadcastToAll((Messageable)myAgent, message);
				}
			});
	}
}
